<?php

/**
 * flag actions.
 *
 * @package    explications_informatiques
 * @subpackage flag
 * @author     Guimezanes Cyrille
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class flagActions extends sfActions
{
  public function executeNew(sfWebRequest $request)
  {
    $this->form = new FlagsForm();
	$this->form->setDefault('id_revision', $request->getParameter('id'));
	$this->form->setDefault('id_asso', $request->getParameter('id2'));
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forwardUnless($request->isMethod(sfRequest::POST),"headers","forbidden");

    $this->form = new FlagsForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }
  public function executeDelete(sfWebRequest $request)
  {
    $this->forward404Unless($flags = Doctrine_Core::getTable('Flags')->find(array($request->getParameter('id'))), sprintf('Object flags does not exist (%s).', $request->getParameter('id')));
    $flags->delete();
		//log
		sfCoreAutoload::logElem("Suppression d'un flag id:".$request->getParameter('id'), $this->getUser()->getGuardUser()->getId(), date("Y-m-d h:i:s"));
    $this->redirect('@show_article?title=article&idasso='.$request->getParameter('id2'));
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $flags = $form->save();
	  //log
		sfCoreAutoload::logElem("Ajout d'un flag idasso:".$request["flags"]["id_asso"], $this->getUser()->getGuardUser()->getId(), date("Y-m-d h:i:s"));
      $this->redirect('@show_article?title=article&idasso='.$request["flags"]["id_asso"]);
    }
  }
}
